package com.songcha.module_splash.ui.activity.splash

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.songcha.library_base.interfaces.IApiResult
import com.songcha.library_business.bean.advert.AdvertInfoBean
import com.songcha.library_business.bean.configuration.SystemConfigurationBean
import com.songcha.library_business.bean.configuration.SystemConfigurationResultBean
import com.songcha.library_business.bean.user.UserInfoBean
import com.songcha.library_business.config.FunctionConfig
import com.songcha.library_business.config.VarConfig
import com.songcha.library_business.proxy.configuration.SystemConfigurationManager
import com.songcha.library_business.proxy.userinfo.UserInfoManager
import com.songcha.library_business.viewmodel.BaseErrorViewModel
import com.songcha.library_common.LibraryCommon
import com.songcha.library_common.util.PackageUtil
import com.songcha.library_network.bean.BaseBean
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class SplashViewModel(app: Application):BaseErrorViewModel<SplashRepository>(app) {
    //var isAgreeUserPolicy=0

    val skipCountDown= MutableLiveData<Int>()
    val advertState=MutableLiveData<Boolean>()

    fun updateClientIp(){
        handleApiDataObserver(repository!!.updateClientIp(),object:IApiResult<BaseBean>{
            override fun onSuccess(bean: BaseBean) {

            }

        },false,false,false)
    }

    fun getUserInfo(){
        handleApiDataObserver(repository!!.getUserInfo(),object:IApiResult<UserInfoBean>{
            override fun onSuccess(bean: UserInfoBean) {
                UserInfoManager.saveUserInfo(bean.data)
            }

        },false,false,false)
    }


    fun getSystemConfiguration(){
        handleApiDataObserver(SystemConfigurationManager.getSystemConfiguration(),object:IApiResult<SystemConfigurationResultBean>{
            override fun onSuccess(bean: SystemConfigurationResultBean) {
                advertState.value = bean.advertState && VarConfig.ADVERT_SPLASH_INFO.type != AdvertInfoBean.ADVERT_TYPE_DIS_ENABLED
            }

            override fun onError(e: Throwable) {
                advertState.value = false
            }

        },false,false,false)
    }


    fun setCountDown(countDown:Int){
        skipCountDown.value=countDown
    }
}